#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <omp.h>
#include "mpi.h"

#include "openmp/tournament.h"
#include "openmpi/treebarrier.h"

static int my_rk; // debug

void init_combined_barrier(int nump, int numm, int rk)
{
    init_tournament_barrier_omp(nump);
    init_tree_barrier_mpi(numm, rk);
    my_rk = rk;
}

void combined_barrier()
{
    tournament_barrier_omp();
    if (omp_get_thread_num() == 0) { // Only the root node can start the MPI barrier
        mpi_tree_barrier();
    }
    release_barrier_omp();
}

